<template>
  <div id="app">
    <transition :name="transitionName">
      <router-view />
    </transition>
  </div>
</template>
<script>
import FastClick from 'fastclick'
import 'animate.css'
export default {
  data() {
    return {
      transitionName: 'slide-right',
      activeName: '',
    }
  },
  created() {
    // 判断 用户是否登录
    if (this.$store.getters.getIsLogin) {
      // 已登录 刷新之后 获取用户信息
      this.$store.dispatch('getInfo')
      this.$store.dispatch('getCarDataList')
    }
  },
  watch: {
    $route: function (newValue, oldValue) {
      // console.log(newValue)
      if (newValue.meta.index < oldValue.meta.index) {
        // console.log('向右的动画');
        // console.log('---')
        // this.activeName = 'animate__fadeInLeft'
        this.transitionName = 'slide-right'
        // console.log(this)
      } else if (newValue.meta.index > oldValue.meta.index) {
        // console.log('向左的动画');
        // this.activeName = 'animate__fadeInRight'
        this.transitionName = 'slide-left'
      } else {
        // console.log('同等级页面切换');
        this.transitionName = ''
      }
      // console.log(this.activeName)
    },
  },
  mounted() {
    //解决移动端点击300ms延时
    FastClick.attach(document.body)
  },
}
</script>
<style lang="scss">
#app {
  width: 100%;
  max-width: 800px;
  height: 100%;
  margin: 0 auto;
  background: #fff;
  -webkit-overflow-scrolling: touch;
  position: absolute;
  left: 0;
  top: 0;
}

/*切换样式出错处理*/
.router-view {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  bottom: 0;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}
/*切换动画*/
/*
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  animation-duration: 1s;
}

.slide-right-enter,
.slide-left-leave-active {
  animation: animate__fadeInLeft; 
}

.slide-right-leave-active,
.slide-left-enter {
  animation: animate__fadeInRight;
}*/
.slide-right-enter-active,
.slide-right-leave-to,
.slide-left-enter-active,
.slide-left-leave-to {
  will-change: transform;
  transition: all 600ms ease;
}

.slide-right-enter,
.slide-left-leave-to {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}

.slide-right-leave-to,
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
</style>
